package com.java.IO.object_stream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

public class ObjectInputStreamAPI {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        String path = "File和IO流\\com\\java\\files\\byte_stream.txt";
        
        // 创建对象：创建规则主要依赖于构造形参InputStream的子类
        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(path));
        
        // readXxx：读取目标地内Java对象，若无数据则抛出异常EOFException。实现读取全部对象可将所有对象存于List中，对List实现反序列化和序列化即可
        System.out.println(objectInputStream.readObject()); // SYX-0-男
        System.out.println(objectInputStream.readObject()); // LYW-0-男
        
        // close：关闭流并释放资源
        objectInputStream.close();
    }
}
